/**
 * 
 */
package com.qolome.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qolome.dao.model.PasswdBook;
import com.qolome.dto.request.AccountDtoCreateRequest;
import com.qolome.dto.request.AccountDtoQueryRequest;
import com.qolome.dto.request.AccountGetPassword;
import com.qolome.enums.ResultEnum;
import com.qolome.service.AccountService;
import com.qolome.utils.web.ErrReturnUtils;
import com.qolome.utils.web.HttpResult;

/**
 * @Description:帐号控制层
 * @author 姜锋
 * @date 2020年1月4日 下午1:20:58
 * @version V1.0
 */
@RestController
@RequestMapping("/account")
public class AccountController {
	@Autowired
	AccountService accountService;
	
	@PostMapping("/create")
	public HttpResult<Void> create(@RequestBody @Valid AccountDtoCreateRequest request,BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ErrReturnUtils.returnError(bindingResult.getAllErrors());
		}
		accountService.create(request);
		return HttpResult.resultEnum(ResultEnum.SUCCESS, null);
	}
	
	@GetMapping("/list")
	public HttpResult<List<PasswdBook>> list(@RequestBody @Valid AccountDtoQueryRequest accountDtoQueryRequest,BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ErrReturnUtils.returnError(bindingResult.getAllErrors());
		}
		return HttpResult.success(accountService.list(accountDtoQueryRequest), null);
	}
	
	@PostMapping("/getPassword")
	public HttpResult<PasswdBook> getPassword(@RequestBody @Valid AccountGetPassword request,BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ErrReturnUtils.returnError(bindingResult.getAllErrors());
		}
		return accountService.getPassword(request);
	}
	
	@PostMapping("/updatePassword")
	public void updatePassword() {
		 accountService.updatePassword();
	}
}
